package cn.fl.spdealer.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.constant.PrjLnkCompConstant;
import cn.fl.spdealer.service.ISplGroupService;
import cn.fl.spdealer.transform.SplGroupVOTransform;
import cn.fl.spdealer.vo.SplGroupVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.customer.facade.customer.condition.CstBscInfoQueryCondition;
import fl.flow.facade.flow.api.IFlowApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.spl.facade.framework.constant.DictionaryConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.SplGrpRelTypCdEnum;
import fl.spl.facade.grpcfg.api.ISplGrpPrjBizViewApiService;
import fl.spl.facade.grpcfg.api.ISplGrpRelInfoApiService;
import fl.spl.facade.grpcfg.condition.SplGrpPrjBizViewQC;
import fl.spl.facade.grpcfg.condition.SplGrpRelInfoQC;
import fl.spl.facade.grpcfg.dto.SplGrpPrjBizViewDTO;
import fl.spl.facade.grpcfg.dto.SplGrpRelInfoDTO;
import fl.spl.facade.lnkcomp.api.IPrjLnkCompQueryApiService;
import fl.spl.facade.lnkcomp.api.IPrjLnkCompRlPsnQueryApiService;
import fl.spl.facade.lnkcomp.condition.PrjLnkCompQueryCondition;
import fl.spl.facade.lnkcomp.condition.PrjLnkCompRlPsnQC;
import fl.spl.facade.lnkcomp.dto.PrjLnkCompDTO;
import fl.spl.facade.lnkcomp.dto.PrjLnkCompRlPsnDTO;
import fl.spl.facade.spl.api.ISplInfoApiService;
import fl.spl.facade.spl.condition.SplInfoQueryCondition;
import fl.spl.facade.spl.condition.SplRlPsnQueryCondition;
import fl.spl.facade.spl.constant.SplInfoConstant;
import fl.spl.facade.spl.dto.SplInfoDTO;
import fl.spl.facade.spl.dto.SplRlPsnDTO;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import sp.dealer.facade.dealer.condition.SplGroupQC;
import sp.dealer.facade.dealer.dto.SplGroupDTO;
import sp.dealer.facade.framework.enums.SplGroupSplTypCdEnum;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description: 经销商集团划分（包括 经销商 和挂靠公司） 控制层
 */
@Controller
@RequestMapping("/splGroup")
public class SplGroupController extends BaseController {

    /**
     * SplGroup 服务层BEAN
     */
    @Autowired
    private ISplGroupService splGroupService;

    @Autowired
    private ISplGrpRelInfoApiService splGrpRelInfoApiService;

    @Autowired
    private ISplInfoApiService splInfoApiService;

    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    @Autowired
    private IFlowApiService flowApiService;

    @Autowired
    private ISplGrpPrjBizViewApiService splGrpPrjBizViewApiService;

    @Autowired
    private IPrjLnkCompRlPsnQueryApiService prjLnkCompRlPsnQueryApiService ;

    @Autowired
    private ICstBscInfoService cstBscInfoService;

    @Autowired
    private IPrjLnkCompQueryApiService prjLnkCompQueryApiService ;

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        String splTypCd = request.getParameter("splTypCd");
        String groupId = request.getParameter("groupId");
        ModelAndView view = new ModelAndView();
        if (StringUtils.isNotEmpty(splTypCd) && !splTypCd.equals(SplGroupSplTypCdEnum.GROUP.getSplTypCd())) {
            view.setViewName("/spdealer/splGroup/splGroupMemberListPage");
        } else {
            view.setViewName("/spdealer/splGroup/splGroupListPage");
        }
        view.addObject("groupId", groupId);
        view.addObject("splTypCd", splTypCd);
        BaseLogUtils.newWebLogger("跳转到列表页面.").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();

        return view;
    }

    /**
     * 到集团经销业务统计页面
     */
    @RequestMapping(value = "/toSplAnalysisPage.do", method = {RequestMethod.GET})
    public ModelAndView toSplAnalysisPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("/spdealer/splAnalysis/splAnalysisPage");
        return view;
    }

    /**
     * 到集团挂靠业务统计页面
     */
    @RequestMapping(value = "/toLnkCompAnalysisPage.do", method = {RequestMethod.GET})
    public ModelAndView toLnkCompAnalysisPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("/spdealer/splAnalysis/lnkCompAnalysisPage");
        return view;
    }

    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");
        ModelAndView view = new ModelAndView("/splGroup/modify");
        view.addObject("id", id);
        return view;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object initList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String groupId = request.getParameter("groupId");
        String splNm = request.getParameter("splNm");
        String relInfo = request.getParameter("relInfo");
        String relTypCd = request.getParameter("relTypCd");
        String splTypCd = request.getParameter("splTypCd");
        String memberNm = request.getParameter("memberNm");

        boolean flag = true;
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        } else {
            page.setCurrentPage(1);
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        } else {
            page.setEveryPage(10);
        }
        SplGroupQC qc = new SplGroupQC();
        qc.setIsDel(BaseConstant.IS_YESNO_NO);
        qc.setIsValid(BaseConstant.IS_YESNO_YES);
        qc.setIsCancel(BaseConstant.IS_YESNO_NO);
        if (StringUtils.isNotEmpty(groupId)) {
            qc.setId(Long.valueOf(groupId));
        }
        if (StringUtils.isNotEmpty(splNm)) {
            qc.setSplName(splNm);
        }
        if (StringUtils.isNotEmpty(relTypCd)) {
            qc.setRelTypCd(Integer.valueOf(relTypCd));
        }

        if (StringUtils.isNotEmpty(relInfo)) {
            //qc.setRelInfo(relInfo);
            SplGrpRelInfoQC splGrpRelInfoQC = new SplGrpRelInfoQC();
            splGrpRelInfoQC.setSysCd(SplSystemConstant.FL_SYS_CD);
            splGrpRelInfoQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            splGrpRelInfoQC.setChlCd(SplSystemConstant.FL_WEB_CHL_CD);
            splGrpRelInfoQC.setIsDel(BaseConstant.IS_YESNO_NO);
            splGrpRelInfoQC.setIsNew(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setIsValid(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setRelInfo(relInfo);
            List<SplGrpRelInfoDTO> splGrpRelInfoDTOList = this.splGrpRelInfoApiService.searchSplGrpRelInfoDTOList(splGrpRelInfoQC);
            Set<Long> splGrpIds = null;
            if (CollectionUtils.isNotEmpty(splGrpRelInfoDTOList)) {
                splGrpIds = new HashSet<>(splGrpRelInfoDTOList.size());
                for (SplGrpRelInfoDTO dto : splGrpRelInfoDTOList) {
                    splGrpIds.add(dto.getSplGrpId());
                }
                qc.setIdList(new ArrayList<Long>(splGrpIds));
            } else {
                flag = false;
            }
            splGrpRelInfoDTOList = null;
            splGrpIds = null;
        }
        if (StringUtils.isNotEmpty(memberNm)) {
            SplGroupQC qc2 = new SplGroupQC();
            qc2.setSplName(memberNm);
            List<Integer> splTypCds = new ArrayList<>();
            splTypCds.add(SplGroupSplTypCdEnum.SPL.getSplTypCd());
            splTypCds.add(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd());

            qc2.setSplTypCdList(splTypCds);
            qc2.setIsCancel(BaseConstant.IS_YESNO_NO);
            qc2.setIsDel(BaseConstant.IS_YESNO_NO);
            List<SplGroupVO> list = this.splGroupService.searchList(qc2);
            if (CollectionUtils.isNotEmpty(list)) {
                List<Long> groupIds = new ArrayList<>();
                for (SplGroupVO splGroupVO : list) {
                    groupIds.add(splGroupVO.getSplGroupId());
                }
                List<Long> idList = qc.getIdList();
                if (CollectionUtils.isNotEmpty(idList)) {
                    idList.addAll(groupIds);
                    qc.setIdList(idList);
                } else {
                    qc.setIdList(groupIds);
                }
            } else {
                flag = false;
            }
        }
        if (StringUtils.isNotEmpty(splTypCd)) {
            qc.setSplTypCd(Integer.valueOf(splTypCd));
        }
        page.setCondition(qc);

        if (!flag) {
            return new ListPageVO<>();
        }
        //TODO SOMETHING
        Pager pager = this.splGroupService.searchListPage(page);
        List<SplGroupDTO> list = (List<SplGroupDTO>) pager.getResultList();
        List<SplGroupVO> splGroupVOS = SplGroupVOTransform.toVOList(list);
        List<Long> groupIdList = null;
        Map<Long, StringBuilder> groupIdRelInfoMap = null;
        StringBuilder stringBuilder = null;
        if (CollectionUtils.isNotEmpty(splGroupVOS)) {

            groupIdList = new ArrayList<>(splGroupVOS.size());
            groupIdRelInfoMap = new HashMap<>(splGroupVOS.size());
            for (SplGroupVO splGroupVO : splGroupVOS) {
                if (SplGroupSplTypCdEnum.GROUP.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    groupIdList.add(splGroupVO.getId());
                }
                //splGroupVO.setRelInfo(String.valueOf(splGroupVO.getSplId()));
            }
            SplGrpRelInfoQC splGrpRelInfoQC = new SplGrpRelInfoQC();
            splGrpRelInfoQC.setSysCd(SplSystemConstant.FL_SYS_CD);
            splGrpRelInfoQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            splGrpRelInfoQC.setChlCd(SplSystemConstant.FL_WEB_CHL_CD);
            splGrpRelInfoQC.setIsDel(BaseConstant.IS_YESNO_NO);
            splGrpRelInfoQC.setIsNew(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setIsValid(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setSplGrpIdList(groupIdList);
            List<SplGrpRelInfoDTO> splGrpRelInfoDTOList = this.splGrpRelInfoApiService.searchSplGrpRelInfoDTOList(splGrpRelInfoQC);
            for (SplGrpRelInfoDTO dto : splGrpRelInfoDTOList) {
                if (StringUtils.isNotEmpty(dto.getRelInfo())) {
                    if (groupIdRelInfoMap.containsKey(dto.getSplGrpId())) {
                        stringBuilder = groupIdRelInfoMap.get(dto.getSplGrpId());
                    } else {
                        stringBuilder = new StringBuilder();
                    }
                    stringBuilder.append(dto.getRelInfo()).append(";");
                    groupIdRelInfoMap.put(dto.getSplGrpId(), stringBuilder);
                }
            }
            if (CollectionUtils.isMapNotEmpty(groupIdRelInfoMap)) {
                for (SplGroupVO splGroupVO : splGroupVOS) {
                    if (SplGroupSplTypCdEnum.GROUP.getSplTypCd().equals(splGroupVO.getSplTypCd())
                            && groupIdRelInfoMap.containsKey(splGroupVO.getId())) {
                        splGroupVO.setRelInfo(String.valueOf(groupIdRelInfoMap.get(splGroupVO.getId())));
                    }
                }
            }
            SplGroupQC condition = new SplGroupQC();
            List<Integer> splTypCdList = new ArrayList<>();
            condition.setSplGrpIdList(groupIdList);
            splTypCdList.add(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd());
            splTypCdList.add(SplGroupSplTypCdEnum.SPL.getSplTypCd());
            condition.setSplTypCdList(splTypCdList);
            condition.setIsDel(BaseConstant.IS_YESNO_NO);
            condition.setIsCancel(BaseConstant.IS_YESNO_NO);
            condition.setIsValid(BaseConstant.IS_YESNO_YES);

            List<SplGroupVO> searchList = this.splGroupService.searchList(condition);
            Map<Long, Long> splMap = new HashMap<>();
            Map<Long, Long> prjMap = new HashMap<>();
            List<Long> splIds = new ArrayList<>();
            List<Long> prjIds = new ArrayList<>();
            for (SplGroupVO splGroupVO : searchList) {
                if (splGroupVO.getSplTypCd() != null && splGroupVO.getSplTypCd().equals(SplGroupSplTypCdEnum.SPL.getSplTypCd())) {
                    splIds.add(splGroupVO.getSplId());
                    splMap.put(splGroupVO.getSplId(), splGroupVO.getSplGroupId());
                } else if (splGroupVO.getSplTypCd() != null && splGroupVO.getSplTypCd().equals(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd())) {
                    prjIds.add(splGroupVO.getSplId());
                    prjMap.put(splGroupVO.getSplId(), splGroupVO.getSplGroupId());
                }
            }
            if (CollectionUtils.isNotEmpty(splIds)) {
                SplGrpPrjBizViewQC viewQC = new SplGrpPrjBizViewQC();
                viewQC.setSplIdList(splIds);
                viewQC.setSplTypCd(SplGroupSplTypCdEnum.SPL.getSplTypCd());
                List<SplGrpPrjBizViewDTO> searchSplGrpAnalysisData = this.splGrpPrjBizViewApiService.searchSplGrpAnalysisData(viewQC);
                BaseLogUtils.newWebLogger("查询经销业务,data:" + JSON.toJSONString(searchSplGrpAnalysisData))
                        .setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .info();
                if (CollectionUtils.isNotEmpty(searchSplGrpAnalysisData)) {
                    HashMap<Long, Long> hashMap = new HashMap<>();
                    for (SplGrpPrjBizViewDTO splGrpPrjBizViewDTO : searchSplGrpAnalysisData) {
                        Long groupId1 = splMap.get(splGrpPrjBizViewDTO.getDataId());
                        if (hashMap.containsKey(groupId1)) {
                            hashMap.put(groupId1, hashMap.get(groupId1) + splGrpPrjBizViewDTO.getRepayExpoAmt());
                        } else {
                            hashMap.put(groupId1, splGrpPrjBizViewDTO.getRepayExpoAmt());
                        }
                    }

                    for (SplGroupVO splGroup : splGroupVOS) {
                        splGroup.setSplOpenTotal(hashMap.get(splGroup.getId()));
                    }
                }

            }
            if (CollectionUtils.isNotEmpty(prjIds)) {
                SplGrpPrjBizViewQC viewQC = new SplGrpPrjBizViewQC();
                viewQC.setLnkCompIdList(prjIds);
                viewQC.setSplTypCd(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd());
                List<SplGrpPrjBizViewDTO> searchSplGrpAnalysisData = this.splGrpPrjBizViewApiService.searchSplGrpAnalysisData(viewQC);
                BaseLogUtils.newWebLogger("查询挂靠业务,data:" + JSON.toJSONString(searchSplGrpAnalysisData)).setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .info();
                if (CollectionUtils.isNotEmpty(searchSplGrpAnalysisData)) {
                    HashMap<Long, Long> hashMap = new HashMap<>();
                    for (SplGrpPrjBizViewDTO splGrpPrjBizViewDTO : searchSplGrpAnalysisData) {
                        Long groupId1 = prjMap.get(splGrpPrjBizViewDTO.getDataId());
                        if (hashMap.containsKey(groupId1)) {
                            hashMap.put(groupId1, hashMap.get(groupId1) + splGrpPrjBizViewDTO.getRepayExpoAmt());
                        } else {
                            hashMap.put(groupId1, splGrpPrjBizViewDTO.getRepayExpoAmt());
                        }
                    }

                    for (SplGroupVO splGroup : splGroupVOS) {
                        splGroup.setPrjOpenTotal(hashMap.get(splGroup.getId()));
                    }
                }
            }

        }
        List<Integer> splTypCdList = new ArrayList<>();
        splTypCdList.add(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd());
        splTypCdList.add(SplGroupSplTypCdEnum.SPL.getSplTypCd());
        SplGroupQC condition = new SplGroupQC();
        condition.setSplTypCdList(splTypCdList);
        condition.setIsCancel(BaseConstant.IS_YESNO_NO);
        condition.setIsDel(BaseConstant.IS_YESNO_NO);
        condition.setIsValid(BaseConstant.IS_YESNO_YES);
        for (SplGroupVO splGroupVO : splGroupVOS) {
            //集团成员数量
            condition.setSplGroupId(splGroupVO.getId());
            int seachSplGroupCountByQC = this.splGroupService.seachSplGroupCountByQC(condition);
            splGroupVO.setCount(seachSplGroupCountByQC);


        }
        this.addGroupAsSure(splGroupVOS);
        ListPageVO<SplGroupVO> listPage = new ListPageVO<SplGroupVO>(splGroupVOS, pager.getTotalCount());
        BaseLogUtils.newWebLogger("查询数据完成. DATA:" + JSONObject.toJSONString(page)).setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        return listPage;
    }


    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toSplGroupMemberListPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object splGroupMemberListPage(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String groupId = request.getParameter("groupId");
        String splNm = request.getParameter("splNm");
        String relInfo = request.getParameter("relInfo");
        String relTypCd = request.getParameter("relTypCd");
        String splTypCd = request.getParameter("splTypCd");
        String audStsCd = request.getParameter("audStsCd");
        String isAddMember = request.getParameter("isAddMember");

        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        SplGroupQC qc = new SplGroupQC();
        qc.setIsValid(BaseConstant.IS_YESNO_YES);
        qc.setIsDel(BaseConstant.IS_YESNO_NO);
        if (StringUtils.isNotEmpty(groupId)) {
            qc.setSplGroupId(Long.valueOf(groupId));
            qc.setIsCancel(BaseConstant.IS_YESNO_NO);
        }
		/*if (StringUtils.isNotEmpty(groupId)) {
			qc.setId(Long.valueOf(groupId));
		}*/

        if (StringUtils.isNotEmpty(splNm)) {
            qc.setSplName(splNm);
        }
        if (StringUtils.isNotEmpty(relTypCd)) {
            qc.setRelTypCd(Integer.valueOf(relTypCd));
        }
        if (StringUtils.isNotEmpty(audStsCd)) {
            qc.setAudStsCd(audStsCd);
        }
        if (StringUtils.isNotEmpty(relInfo)) {
            qc.setRelInfo(relInfo);
            SplGrpRelInfoQC splGrpRelInfoQC = new SplGrpRelInfoQC();
            splGrpRelInfoQC.setSysCd(SplSystemConstant.FL_SYS_CD);
            splGrpRelInfoQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            splGrpRelInfoQC.setChlCd(SplSystemConstant.FL_WEB_CHL_CD);
            splGrpRelInfoQC.setIsDel(BaseConstant.IS_YESNO_NO);
            splGrpRelInfoQC.setIsNew(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setIsValid(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setRelInfo(relInfo);
            if (StringUtils.isNotEmpty(groupId)) {
                splGrpRelInfoQC.setSplGrpId(Long.valueOf(groupId));
            }
            page.setCondition(splGrpRelInfoQC);
            Pager pageResult = this.splGrpRelInfoApiService.searchSplGrpRelInfoDTOByPage(page);
            List<SplGrpRelInfoDTO> splGrpRelInfoDTOList = (List<SplGrpRelInfoDTO>) pageResult.getResultList();
            Set<Long> splIds = null;
            if (CollectionUtils.isNotEmpty(splGrpRelInfoDTOList)) {
                splIds = new HashSet<>(splGrpRelInfoDTOList.size());
                for (SplGrpRelInfoDTO dto : splGrpRelInfoDTOList) {
                    splIds.add(dto.getRelMemberId());
                }
                qc.setSplIdList(new ArrayList<Long>(splIds));
            } else {
                return new ListPageVO<>();
            }
            page.setCondition(null);
            page.setResultList(null);
            splGrpRelInfoDTOList = null;
            pageResult = null;
            splIds = null;
        }
        if (StringUtils.isNotEmpty(splTypCd) && !splTypCd.equals(SplGroupSplTypCdEnum.GROUP.getSplTypCd())) {
            if (splTypCd.equals(SplGroupSplTypCdEnum.SPL.getSplTypCd()) || splTypCd.equals(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd())) {
                qc.setSplTypCd(Integer.valueOf(splTypCd));
            } else {
                List<Integer> splTypCdList = new ArrayList<>();
                splTypCdList.add(SplGroupSplTypCdEnum.SPL.getSplTypCd());
                splTypCdList.add(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd());
                qc.setSplTypCdList(splTypCdList);
            }
        }
        page.setCondition(qc);

        //TODO SOMETHING
        Pager pager = this.splGroupService.searchListPage(page);
        List<SplGroupDTO> list = (List<SplGroupDTO>) pager.getResultList();
        List<SplGroupVO> splGroupVOS = SplGroupVOTransform.toVOList(list);
        List<Long> splIdList = null;
        Map<Long, String> splIdSplLvlCdNm = null;
        Map<String, String> splLvlCdNmMap = null;
        if (CollectionUtils.isNotEmpty(splGroupVOS)) {
            List<Long> memberIds = new ArrayList<>(list.size());
            Map<Long, SplGroupVO> splGroupVOMap = new HashMap<>(list.size());
            splIdList = new ArrayList<>(list.size());
            for (SplGroupVO splGroupVO : splGroupVOS) {
                memberIds.add(splGroupVO.getSplId());
                splGroupVO.setSplTypCdNm(SplGroupSplTypCdEnum.getSplTypCdNmByCd(splGroupVO.getSplTypCd()));
                splGroupVOMap.put(splGroupVO.getSplId(), splGroupVO);
                if (SplGroupSplTypCdEnum.SPL.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    splIdList.add(splGroupVO.getSplId());
                }
            }

            SplGrpRelInfoQC splGrpRelInfoQC = new SplGrpRelInfoQC();
            splGrpRelInfoQC.setSysCd(SplSystemConstant.FL_SYS_CD);
            splGrpRelInfoQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            splGrpRelInfoQC.setChlCd(SplSystemConstant.FL_WEB_CHL_CD);
            splGrpRelInfoQC.setIsDel(BaseConstant.IS_YESNO_NO);
            splGrpRelInfoQC.setIsNew(BaseConstant.IS_YESNO_YES);
            splGrpRelInfoQC.setIsValid(BaseConstant.IS_YESNO_YES);
            //splGrpRelInfoQC.setReMemberIdList(memberIds);
            splGrpRelInfoQC.setRelMemberIdList(memberIds);
            if (StringUtils.isNotEmpty(groupId)) {
                splGrpRelInfoQC.setSplGrpId(Long.valueOf(groupId));
            }
            List<SplGrpRelInfoDTO> splGrpRelInfoDTOList = this.splGrpRelInfoApiService.searchGrpMemberRelInfoDTO(splGrpRelInfoQC);

            Map<String, SplGrpRelInfoDTO> map = new HashMap<>();
            if (CollectionUtils.isNotEmpty(splGrpRelInfoDTOList)) {
                for (SplGrpRelInfoDTO splGrpRelInfoDTO : splGrpRelInfoDTOList) {
                    String string = splGrpRelInfoDTO.getRelMemberId().toString();
                    string += splGrpRelInfoDTO.getRelSplTypCd();
                    map.put(string, splGrpRelInfoDTO);
						/* List<SplGrpRelInfoDTO> list2 = map.get(splGrpRelInfoDTO.getRelMemberId());
						if(CollectionUtils.isEmpty(list2)){
							list2 = new ArrayList<>();
						}
						list2.add(splGrpRelInfoDTO);
						map.put(splGrpRelInfoDTO.getRelMemberId(), list2);*/
                }
                for (SplGroupVO splGroupVO : splGroupVOS) {
                    String string = splGroupVO.getSplId().toString();
                    string += splGroupVO.getSplTypCd();
                    SplGrpRelInfoDTO dto = map.get(string);
						/*SplGrpRelInfoDTO dto = null;
						if(CollectionUtils.isNotEmpty(list2)){
							for (SplGrpRelInfoDTO splGrpRelInfoDTO : list2) {
								if(StringUtils.isNotEmpty(splGrpRelInfoDTO.getRelSplTypCd()) 
										&& splGrpRelInfoDTO.getRelSplTypCd() == splGroupVO.getSplTypCd() ){
									dto = splGrpRelInfoDTO ;
								}
							}
						}*/
                    if (dto != null) {
                        splGroupVO.setRelInfo(dto.getRelInfo());
                        splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.getRelTypCdNmByCd(dto.getRelTypCd()));
						/*if(SplGrpRelTypCdEnum.COMP_PER_NO.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.COMP_PER_NO.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.TOP_EXECS.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.TOP_EXECS.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.RECEIVE_ACC.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.RECEIVE_ACC.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.REL_ADDR.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.REL_ADDR.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.ADD_MANUAL.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.ADD_MANUAL.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.REL_HIS.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.REL_HIS.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.NP_CST_ACC.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.NP_CST_ACC.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.LP_CST_ACC.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.LP_CST_ACC.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.SELF_REL_SELF.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.SELF_REL_SELF.getRelTypCdNm());
						}else if(SplGrpRelTypCdEnum.COMP_SAME_NM.getRelTypCd().equals(dto.getRelTypCd())){
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.COMP_SAME_NM.getRelTypCdNm());
						}else{
							splGroupVO.setRelTypCdNm(SplGrpRelTypCdEnum.REL_OTHER.getRelTypCdNm());
						}*/
                    }
                }
                for (SplGrpRelInfoDTO dto : splGrpRelInfoDTOList) {
                    Long memberId = dto.getMemberId();
                    if (splGroupVOMap.containsKey(memberId) && StringUtils.isNotEmpty(dto.getRelTypCd())) {
                    }
                }
            }
            //TODO我司评级
            if (CollectionUtils.isNotEmpty(splIdList)) {
                splIdSplLvlCdNm = new HashMap<>(splIdList.size());
                SplInfoQueryCondition queryCondition = new SplInfoQueryCondition();
                queryCondition.setIsValid(BaseConstant.IS_YESNO_YES);
                queryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
                queryCondition.setIsBlackList(BaseConstant.IS_YESNO_NO);
                queryCondition.setIds(splIdList);
                List<SplInfoDTO> splInfoDTOS = this.splInfoApiService.searchSplInfoList(queryCondition);
                //经销商级别CD-NM
                splLvlCdNmMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.FL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, DictionaryConstant.CODE_SPL_LVL_CD);
                for (SplInfoDTO dto : splInfoDTOS) {
                    if (CollectionUtils.isMapNotEmpty(splLvlCdNmMap) && splLvlCdNmMap.containsKey(dto.getSplLvlCd())) {
                        splIdSplLvlCdNm.put(dto.getId(), splLvlCdNmMap.get(dto.getSplLvlCd()));
                    }
                }
            }

            for (SplGroupVO splGroupVO : splGroupVOS) {
                if (splGroupVOMap.containsKey(splGroupVO.getSplId())) {
                    splGroupVO.setAddrRelInfo(splGroupVOMap.get(splGroupVO.getSplId()).getAddrRelInfo());
                    splGroupVO.setPerRelInfo(splGroupVOMap.get(splGroupVO.getSplId()).getPerRelInfo());
                }
                if (CollectionUtils.isMapNotEmpty(splIdSplLvlCdNm) && splIdSplLvlCdNm.containsKey(splGroupVO.getSplId())) {
                    splGroupVO.setSplLevel(splIdSplLvlCdNm.get(splGroupVO.getSplId()));
                }
            }

            List<Long> splIds = new ArrayList<>();
            List<Long> prjIds = new ArrayList<>();
            for (SplGroupVO splGroupVO : splGroupVOS) {
                if (SplGroupSplTypCdEnum.SPL.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    splIds.add(splGroupVO.getSplId());
                } else if (SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    prjIds.add(splGroupVO.getSplId());
                }
            }
            Map<String, String> audStsCdMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.FL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, DictionaryConstant.CODE_AUD_STS_CD);
            SysFlowSHQueryCondition condition = new SysFlowSHQueryCondition();
            condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
            condition.setStatus(BaseConstant.IS_YESNO_YES);
            List<String> busTypList;
            Map<Long, SysFlowSHDTO> flowSHMap;

            if (CollectionUtils.isNotEmpty(splIds)) {
                //封装供应商审核状态
                busTypList = new ArrayList<>(3);
                flowSHMap = new HashMap<>();
                busTypList.add(SplInfoConstant.INSIDE_SPL_ACCESS_FLOW_MODEL_TYP);
                busTypList.add(SplInfoConstant.OUTSIDE_SPL_ACC_ACCESS_FLOW_MODEL_TYP);
                busTypList.add(SplInfoConstant.OUTSIDE_SPL_ACCESS_FLOW_MODEL_TYP);
                condition.setBusTypList(busTypList);
                condition.setDataIdList(splIdList);
                condition.setWordsInTheTable(SplInfoConstant.SPL_FLOW_S_H_SPL);
                List<SysFlowSHDTO> flowSHDTOList = flowApiService.searchFlowSHDTOList(condition);
                if (CollectionUtils.isNotEmpty(flowSHDTOList)) {
                    for (SysFlowSHDTO sysFlowSHDTO : flowSHDTOList) {
                        flowSHMap.put(sysFlowSHDTO.getDataId(), sysFlowSHDTO);
                    }
                    for (SplGroupVO splGroupVO : splGroupVOS) {
                        if (SplGroupSplTypCdEnum.SPL.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                            SysFlowSHDTO sysFlowSHDTO = flowSHMap.get(splGroupVO.getSplId());
                            if (sysFlowSHDTO != null) {
                                splGroupVO.setAudStsCd(sysFlowSHDTO.getAudStsCd());
                                splGroupVO.setAudStsCdNm(audStsCdMap.get(sysFlowSHDTO.getAudStsCd()));
                            }
                        }
                    }
                }
                //供应商是否黑名单
                Map<Long, SplInfoDTO> splMap = new HashMap<>();
                SplInfoQueryCondition splQC = new SplInfoQueryCondition();
                splQC.setIds(splIds);
                List<SplInfoDTO> searchSplInfoList = this.splInfoApiService.searchSplInfoList(splQC);
                for (SplInfoDTO splInfoDTO : searchSplInfoList) {
                    splMap.put(splInfoDTO.getId(), splInfoDTO);
                }
                for (SplGroupVO splGroupVO : splGroupVOS) {
                    if (SplGroupSplTypCdEnum.SPL.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                        SplInfoDTO splInfoDTO = splMap.get(splGroupVO.getSplId());
                        if (splInfoDTO != null) {
                            splGroupVO.setIsBlackList(splInfoDTO.getIsBlackList());
                        }
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(prjIds) && prjIds.size() != 0) {
                //封装挂靠公司审核状态
                busTypList = new ArrayList<>(1);
                flowSHMap = new HashMap<>();
                busTypList.add(FlowConstant.FLOW_MODEL_TYP_LNK);

                condition.setBusTypList(busTypList);
                condition.setWordsInTheTable(PrjLnkCompConstant.FLOW_S_H_LNK);
                condition.setDataIdList(prjIds);
                List<SysFlowSHDTO> flowSHDTOList = flowApiService.searchFlowSHDTOList(condition);

                if (CollectionUtils.isNotEmpty(flowSHDTOList)) {
                    for (SysFlowSHDTO sysFlowSHDTO : flowSHDTOList) {
                        flowSHMap.put(sysFlowSHDTO.getDataId(), sysFlowSHDTO);
                    }
                    for (SplGroupVO splGroupVO : splGroupVOS) {
                        if (SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                            SysFlowSHDTO sysFlowSHDTO = flowSHMap.get(splGroupVO.getSplId());
                            if (sysFlowSHDTO != null) {
                                splGroupVO.setAudStsCd(sysFlowSHDTO.getAudStsCd());
                                splGroupVO.setAudStsCdNm(audStsCdMap.get(sysFlowSHDTO.getAudStsCd()));
                            }
                        }
                    }
                }
                //挂靠公司是否黑名单
                Map<Long, PrjLnkCompDTO> lnkCompMap = new HashMap<>();
                PrjLnkCompQueryCondition lnkQC = new PrjLnkCompQueryCondition();
                lnkQC.setIdList(prjIds);
                List<PrjLnkCompDTO> lnkCompList = this.prjLnkCompQueryApiService.getPrjLnkCompByCondition(lnkQC);
                if (CollectionUtils.isNotEmpty(lnkCompList)) {
                    for (PrjLnkCompDTO prjLnkCompDTO : lnkCompList) {
                        lnkCompMap.put(prjLnkCompDTO.getId(), prjLnkCompDTO);
                    }
                    for (SplGroupVO splGroupVO : splGroupVOS) {
                        if (SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                            PrjLnkCompDTO lnkCompDTO = lnkCompMap.get(splGroupVO.getSplId());
                            if (lnkCompDTO != null) {
                                splGroupVO.setIsBlackList(lnkCompDTO.getIsBlackList());
                            }
                        }
                    }
                }
            }
            if (StringUtils.isNotEmpty(isAddMember) && isAddMember.equals("1")) {
                
                for (SplGroupVO splGroupVO : splGroupVOS) {
            		if(splGroupVO.getIsCancel() == 1){
            			splGroupVO.setSplGroupId(null);
            		}
            	}

                if (CollectionUtils.isNotEmpty(prjIds)) {
                    PrjLnkCompQueryCondition lnkCompQC = new PrjLnkCompQueryCondition();
                    lnkCompQC.setIdList(prjIds);
                    List<PrjLnkCompDTO> prjLnkCompByCondition = this.prjLnkCompQueryApiService.getPrjLnkCompByCondition(lnkCompQC);
                    Map<Long, PrjLnkCompDTO> lnkCompMap = new HashMap<>();
                    for (PrjLnkCompDTO prjLnkCompDTO : prjLnkCompByCondition) {
                        lnkCompMap.put(prjLnkCompDTO.getId(), prjLnkCompDTO);
                    }
                    for (SplGroupVO splGroupVO : splGroupVOS) {
                        PrjLnkCompDTO prjLnkCompDTO = lnkCompMap.get(splGroupVO.getSplId());
                        if (prjLnkCompDTO != null) {
                            splGroupVO.setAddrRelInfo(prjLnkCompDTO.getRegAddr());
                        }
                    }
                }
                if (CollectionUtils.isNotEmpty(splIds)) {
                    SplInfoQueryCondition splInfoQC = new SplInfoQueryCondition();
                    splInfoQC.setIds(splIds);
                    List<SplInfoDTO> searchSplInfoList = this.splInfoApiService.searchSplInfoList(splInfoQC);
                    Map<Long, SplInfoDTO> splInfoMap = new HashMap<>();
                    for (SplInfoDTO splInfoDTO : searchSplInfoList) {
                        splInfoMap.put(splInfoDTO.getId(), splInfoDTO);
                    }
                    for (SplGroupVO splGroupVO : splGroupVOS) {
                        SplInfoDTO splInfoDTO = splInfoMap.get(splGroupVO.getSplId());
                        if (splInfoDTO != null) {
                            splGroupVO.setAddrRelInfo(splInfoDTO.getRegAddr());
                        }
                    }
                }
                List<Long> groupIds = new ArrayList<>();
                for (SplGroupVO splGroupVO : splGroupVOS) {
                    if(StringUtils.isNotEmpty(splGroupVO.getSplGroupId())){
                        groupIds.add(splGroupVO.getSplGroupId());
                    }
                }
                if(CollectionUtils.isNotEmpty(groupIds)){
                    SplGroupQC groupQC = new SplGroupQC();
                    groupQC.setSplTypCd(SplGroupSplTypCdEnum.GROUP.getSplTypCd());
                    groupQC.setIdList(groupIds);
                    List<SplGroupVO> searchList = this.splGroupService.searchList(groupQC);
                    HashMap<Long, SplGroupVO> hashMap = new HashMap<>();
                    for (SplGroupVO splGroupVO : searchList) {
                        hashMap.put(splGroupVO.getId(), splGroupVO);
                    }
                    for (SplGroupVO splGroupVO : splGroupVOS) {
                        SplGroupVO splGroupVO2 = hashMap.get(splGroupVO.getSplGroupId());
                        if (splGroupVO2 != null) {
                            splGroupVO.setSplGroupNm(splGroupVO2.getSplName());
                        }
                    }
                }
            }

        }

        ListPageVO<SplGroupVO> listPage = new ListPageVO<SplGroupVO>(splGroupVOS, pager.getTotalCount());
        BaseLogUtils.newWebLogger("查询数据完成. DATA:" + JSONObject.toJSONString(page)).setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        return listPage;
    }


    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeById.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            return result;
        }
        try {
            this.splGroupService.removeById(Long.valueOf(id));
            BaseLogUtils.newWebLogger("删除数据.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("删除数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newWebLogger("删除数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }

        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newWebLogger("获取数据,主键不存在.[id=" + id + "]").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }

        try {
            SplGroupVO vo = this.splGroupService.selectById(Long.valueOf(id));
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.newWebLogger("获取数据,数据不存在.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
            result.setData(vo);
            BaseLogUtils.newWebLogger("获取数据.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("获取失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newWebLogger("获取失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }

    /**
     * 新增集团成员
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String memberId = request.getParameter("memberId");//成员ID
        String groupId = request.getParameter("groupId");//集团ID
        String groupId2 = request.getParameter("oldGroupId");//原集团ID
        String isAddAll = request.getParameter("isAddAll");//是否全部添加

        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        if (StringUtils.isEmpty(memberId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("成员ID不能为空！");
            return result;
        }
        if (StringUtils.isEmpty(groupId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("集团ID不能为空！");
            return result;
        }
        try {
            //TODO ADD PARAM
            Long oldGroupId = null;
            if (StringUtils.isNotEmpty(groupId2)) {
                oldGroupId = Long.valueOf(groupId2);
            }else{
            	isAddAll = "0";
            }
            boolean addMember = this.splGroupService.addMember(Long.valueOf(groupId), Long.valueOf(memberId), oldGroupId, Integer.valueOf(isAddAll), CurrentThreadContext.getCurrentUserId());

            if (!addMember) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("添加集团成员失败！");
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
        }

        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            return result;
        }
        SplGroupVO entity = null;
        try {
            entity = new SplGroupVO();
            entity.setId(Long.valueOf(id));
            //entity.setName(name);
            //TODO ADD PARAM
            boolean success = this.splGroupService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("修改对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newWebLogger("修改对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }

    /**
     * 解除成员关系
     */
    @RequestMapping(value = "/toCancelGroupMemberRelation.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO toCancelGroupMemberRelation(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        String ids = request.getParameter("ids");
        String groupId = request.getParameter("groupId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(id) && StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            return result;
        }
        SplGroupQC splGroupQC = new SplGroupQC();
        if (StringUtils.isNotEmpty(ids)) {
            List<Long> idsList = new ArrayList<Long>(8);
            JSONArray idsArray = JSONArray.fromObject(ids);
            for (Object object : idsArray) {
                idsList.add(Long.valueOf(object.toString()));
            }
            splGroupQC.setIdList(idsList);
        }

        if (StringUtils.isNotEmpty(id)) {
            splGroupQC.setId(Long.valueOf(id));
        }

        Map<String, Object> mdfMap = new HashMap<>(4);
        mdfMap.put("isCancel", BaseConstant.IS_YESNO_YES);
        mdfMap.put("mdfUsrId", CurrentThreadContext.getCurrentUserId());
        mdfMap.put("mdfTm", new Date());
        mdfMap.put("groupId", "");
        try {
            this.splGroupService.modifySplGroupVOByQC(splGroupQC, mdfMap);
            BaseLogUtils.newWebLogger("删除数据.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("删除数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newWebLogger("删除数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }


    /**
     * 修改
     */
    @RequestMapping(value = "/modifySplGroupNm.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifySplGroupNm(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        String newSplNm = request.getParameter("newSplNm");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newWebLogger("修改数据,主键不存在.[id=" + id + "]").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }
        try {
            SplGroupQC splGroupQC = new SplGroupQC();
            splGroupQC.setId(Long.valueOf(id));
            Map<String, Object> mdfMap = new HashMap<>(4);
            mdfMap.put("splName", newSplNm);
            mdfMap.put("mdfUsrId", CurrentThreadContext.getCurrentUserId());
            mdfMap.put("mdfTm", new Date());
            boolean success = this.splGroupService.modifySplGroupVOByQC(splGroupQC, mdfMap);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
                BaseLogUtils.newWebLogger("修改失败.[id=" + id + "] ").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
            BaseLogUtils.newWebLogger("修改成功.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();

        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("修改对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newWebLogger("修改对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/toAddSplGroupMember.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object toAddSplGroupMember(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String groupId = request.getParameter("groupId");

        ModelAndView view = new ModelAndView("spdealer/splGroup/addSplGroupMember");

        view.addObject("groupId", groupId);
        return view;

    }

    //封装集团贷款合计
    private void addGroupAsSure(List<SplGroupVO> groupVOs) {

        if (CollectionUtils.isNotEmpty(groupVOs)) {
            //集团ID-集团信息Map
            Map<Long, SplGroupVO> groupIdAndGrpInfoMap = new HashMap<>(groupVOs.size());
            //经销商ID-集团ID
            Map<Long, Long> splIdAndGrpIdMap = new HashMap<>(groupVOs.size());
            //挂靠ID-集团ID
            Map<Long, Long> lnkCompIdAndGrpIdMap = new HashMap<>(groupVOs.size());
            //成员名称集合
            List<String> grpMemberNmList = new ArrayList<>(groupVOs.size());
            //经销商成员名称-集团ID MAP
            HashMap<String, Long> splNameAndGrpIdMap = new HashMap<>(groupVOs.size());
            //挂靠公司成员名称-集团ID MAP
            HashMap<String, Long> lnkNameAndGrpIdMap = new HashMap<>(groupVOs.size());
            //集团ID List
            List<Long> splGrpIdList = new ArrayList<>(groupVOs.size());

            for (SplGroupVO splGroupVO : groupVOs) {
                splGrpIdList.add(splGroupVO.getId());
                groupIdAndGrpInfoMap.put(splGroupVO.getId(), splGroupVO);
            }

            SplGroupQC condition = new SplGroupQC();
            List<Integer> splTypCdList = new ArrayList<>();
            condition.setIsCancel(BaseConstant.IS_YESNO_NO);
            condition.setIsDel(BaseConstant.IS_YESNO_NO);
            condition.setSplGrpIdList(splGrpIdList);
            splTypCdList.add(SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd());
            splTypCdList.add(SplGroupSplTypCdEnum.SPL.getSplTypCd());
            condition.setSplTypCdList(splTypCdList);
            List<SplGroupVO> splGrpMembers = this.splGroupService.searchList(condition);

            for (SplGroupVO splGroupVO : splGrpMembers) {
                if (!SplGroupSplTypCdEnum.GROUP.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    grpMemberNmList.add(splGroupVO.getSplName());
                }
                if (SplGroupSplTypCdEnum.SPL.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    splIdAndGrpIdMap.put(splGroupVO.getSplId(), splGroupVO.getSplGroupId());
                    splNameAndGrpIdMap.put(splGroupVO.getSplName(), splGroupVO.getSplGroupId());
                } else if (SplGroupSplTypCdEnum.LNKCOMP.getSplTypCd().equals(splGroupVO.getSplTypCd())) {
                    lnkCompIdAndGrpIdMap.put(splGroupVO.getSplId(), splGroupVO.getSplGroupId());
                    lnkNameAndGrpIdMap.put(splGroupVO.getSplName(), splGroupVO.getSplGroupId());
                }
            }

            //集团ID-客户IDLIST MAP
            HashMap<Long, List<Long>> grpIdAndCstIdsMap = new HashMap<>();
            //客户ID 集合
            List<Long> cstIdlist = null ;
            //根据集团成员名称查询担保人集合
            if (CollectionUtils.isNotEmpty(grpMemberNmList)) {
                CstBscInfoQueryCondition cstQC = new CstBscInfoQueryCondition();
                List<CstBscInfoVO> searchListByCon = null;
                //客户名称分组查询客户信息
                List<List<String>> grpMemberNmsList = null ;
                if(grpMemberNmList.size() > 1000){
                    int recycleTimes = grpMemberNmList.size() % 800 == 0 ? grpMemberNmList.size()/800 : grpMemberNmList.size()/800 + 1 ;
                    grpMemberNmsList = new ArrayList<>(recycleTimes);
                    List<String> memberNms = null ;
                    int index = 0;
                    for(String memberNm : grpMemberNmList){
                        ++index;
                        if(index == 1 || index % 800 == 0 ){
                            if(index % 800 == 0){
                                grpMemberNmsList.add(memberNms);
                            }
                            memberNms = new ArrayList<>(800);
                        }
                        memberNms.add(memberNm);
                        if(index == grpMemberNmList.size()){
                            grpMemberNmsList.add(memberNms);
                        }
                    }
                    for(List<String> memberNmList : grpMemberNmsList){
                        cstQC.setCustNmAlls(memberNmList);
                        if(null == searchListByCon){
                            searchListByCon = this.cstBscInfoService.searchListByCon(cstQC);
                        }else{
                            searchListByCon.addAll(this.cstBscInfoService.searchListByCon(cstQC));
                        }
                    }
                }else{
                    cstQC.setCustNmAlls(grpMemberNmList);
                    searchListByCon = this.cstBscInfoService.searchListByCon(cstQC);
                }
                if (CollectionUtils.isNotEmpty(searchListByCon)) {
                    for (CstBscInfoVO cstBscInfoVO : searchListByCon) {
                        if(splNameAndGrpIdMap.containsKey(cstBscInfoVO.getCstNm())){
                            if (StringUtils.isNotEmpty(splNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()))) {
                                if(grpIdAndCstIdsMap.containsKey(splNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()))){
                                    cstIdlist = grpIdAndCstIdsMap.get(splNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()));
                                }else{
                                    cstIdlist = new ArrayList<>(8);
                                }
                                cstIdlist.add(cstBscInfoVO.getId());
                                grpIdAndCstIdsMap.put(splNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()), cstIdlist);
                            }
                        }
                        if(lnkNameAndGrpIdMap.containsKey(cstBscInfoVO.getCstNm())){
                            if (StringUtils.isNotEmpty(lnkNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()))) {
                                if(grpIdAndCstIdsMap.containsKey(lnkNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()))){
                                    cstIdlist = grpIdAndCstIdsMap.get(lnkNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()));
                                }else{
                                    cstIdlist = new ArrayList<>(8);
                                }
                                cstIdlist.add(cstBscInfoVO.getId());
                                grpIdAndCstIdsMap.put(lnkNameAndGrpIdMap.get(cstBscInfoVO.getCstNm()), cstIdlist);
                            }
                        }
                    }
                }
            }
            //客户身份证号list
            List<String> certNoList = new ArrayList<>();

            //根据供应商联系人查询担保人集合
            if (CollectionUtils.isMapNotEmpty(splIdAndGrpIdMap)) {
                //经销商联系人身份证号-经销商ID LIST
                Map<String, List<Long>> rlPsnCertNoAndSplIdsMap = null ;

                SplRlPsnQueryCondition qc = new SplRlPsnQueryCondition();
                qc.setSplIdList(new ArrayList<>(splIdAndGrpIdMap.keySet()));
                qc.setIsDel(BaseConstant.IS_YESNO_NO);
                List<SplRlPsnDTO> searchPrdSplRlPsnList = this.splInfoApiService.searchPrdSplRlPsnList(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
                List<Long> splIdList = null ;
                if(CollectionUtils.isNotEmpty(searchPrdSplRlPsnList)){
                    rlPsnCertNoAndSplIdsMap =  new HashMap<>(searchPrdSplRlPsnList.size());
                    for (SplRlPsnDTO splRlPsnDTO : searchPrdSplRlPsnList) {
                        if (StringUtils.isNotEmpty(splRlPsnDTO.getCertNo())) {
                            certNoList.add(splRlPsnDTO.getCertNo());
                            if(rlPsnCertNoAndSplIdsMap.containsKey(splRlPsnDTO.getCertNo())){
                                splIdList = rlPsnCertNoAndSplIdsMap.get(splRlPsnDTO.getCertNo());
                            }else{
                                splIdList = new ArrayList<>(8);
                            }
                            if(!splIdList.contains(splRlPsnDTO.getSplId())){
                                splIdList.add(splRlPsnDTO.getSplId());
                                rlPsnCertNoAndSplIdsMap.put(splRlPsnDTO.getCertNo(), splIdList);
                            }
                        }
                    }

                    if (CollectionUtils.isNotEmpty(certNoList)) {
                        CstBscInfoQueryCondition cstQC = new CstBscInfoQueryCondition();
                        //客户身份证号分组查询客户信息
                        List<List<String>> grpMemberCertNosList = null ;
                        List<CstBscInfoVO> cstBscInfoVOList = null ;
                        if(certNoList.size() > 1000){
                            int recycleTimes = certNoList.size() % 800 == 0 ? certNoList.size()/800 : certNoList.size()/800 + 1 ;
                            grpMemberCertNosList = new ArrayList<>(recycleTimes);
                            List<String> certNos = null ;
                            int index = 0;
                            for(String certNo : certNoList){
                                ++index;
                                if(index == 1 || index % 800 == 0 ){
                                    if(index % 800 == 0){
                                        grpMemberCertNosList.add(certNos);
                                    }
                                    certNos = new ArrayList<>(800);
                                }
                                certNos.add(certNo);
                                if(index == certNoList.size()){
                                    grpMemberCertNosList.add(certNos);
                                }
                            }
                            for(List<String> memberCertNoList : grpMemberCertNosList){
                                cstQC.setCertNoList(memberCertNoList);
                                if(null == cstBscInfoVOList){
                                    cstBscInfoVOList = this.cstBscInfoService.searchListByCon(cstQC);
                                }else{
                                    cstBscInfoVOList.addAll(this.cstBscInfoService.searchListByCon(cstQC));
                                }
                            }
                        }else{
                            cstQC.setCertNoList(certNoList);
                            cstBscInfoVOList = cstBscInfoService.searchListByCon(cstQC);
                        }
                        if (CollectionUtils.isNotEmpty(cstBscInfoVOList)) {
                            for (CstBscInfoVO cstBscInfoVO : cstBscInfoVOList) {
                                if(rlPsnCertNoAndSplIdsMap.containsKey(cstBscInfoVO.getCertNo())){
                                    splIdList = rlPsnCertNoAndSplIdsMap.get(cstBscInfoVO.getCertNo());
                                }else{
                                    splIdList = null ;
                                }
                                if(null != splIdList){
                                    for (Long splId : splIdList) {
                                        if (splIdAndGrpIdMap.containsKey(splId)) {
                                            if (grpIdAndCstIdsMap.containsKey(splIdAndGrpIdMap.get(splId))) {
                                                cstIdlist = grpIdAndCstIdsMap.get(splIdAndGrpIdMap.get(splId));
                                            }else{
                                                cstIdlist = new ArrayList<>();
                                            }
                                            if(!cstIdlist.contains(cstBscInfoVO.getId())){
                                                cstIdlist.add(cstBscInfoVO.getId());
                                                grpIdAndCstIdsMap.put(splIdAndGrpIdMap.get(splId), cstIdlist);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        certNoList.clear();
                    }
                }
            }

            //根据挂靠联系人查询担保人集合
            if (CollectionUtils.isMapNotEmpty(lnkCompIdAndGrpIdMap)) {
                //挂靠公司联系人身份证号-经销商ID LIST
                Map<String, List<Long>> rlPsnCertNoAndLnkIdsMap = null ;
                PrjLnkCompRlPsnQC qc = new PrjLnkCompRlPsnQC();
                qc.setLnkCompIdList(new ArrayList<Long>(lnkCompIdAndGrpIdMap.keySet()));
                qc.setIsDel(BaseConstant.IS_YESNO_NO);
                List<PrjLnkCompRlPsnDTO> prjLnkCompRlPsnDTOList = this.prjLnkCompRlPsnQueryApiService.searchLists(qc);
                List<Long> lnkCompIdList = null ;
                if (CollectionUtils.isNotEmpty(prjLnkCompRlPsnDTOList)) {
                    rlPsnCertNoAndLnkIdsMap = new HashMap<>(prjLnkCompRlPsnDTOList.size());
                    for (PrjLnkCompRlPsnDTO lnkPsnDTO : prjLnkCompRlPsnDTOList) {
                        if (StringUtils.isNotEmpty(lnkPsnDTO.getCertNo())) {
                            certNoList.add(lnkPsnDTO.getCertNo());
                            if(rlPsnCertNoAndLnkIdsMap.containsKey(lnkPsnDTO.getCertNo())){
                                lnkCompIdList = rlPsnCertNoAndLnkIdsMap.get(lnkPsnDTO.getCertNo());
                            }else{
                                lnkCompIdList = new ArrayList<>();
                            }
                            if(!lnkCompIdList.contains(lnkPsnDTO.getPrjLnkCompId())){
                                lnkCompIdList.add(lnkPsnDTO.getPrjLnkCompId());
                                rlPsnCertNoAndLnkIdsMap.put(lnkPsnDTO.getCertNo(), lnkCompIdList);
                            }
                        }
                    }
                }

                if (CollectionUtils.isNotEmpty(certNoList)) {
                    CstBscInfoQueryCondition cstQC = new CstBscInfoQueryCondition();
                    //客户身份证号分组查询客户信息
                    List<List<String>> grpMemberCertNosList = null ;
                    List<CstBscInfoVO> cstBscInfoVOList = null ;
                    if(certNoList.size() > 1000){
                        int recycleTimes = certNoList.size() % 800 == 0 ? certNoList.size()/800 : certNoList.size()/800 + 1 ;
                        grpMemberCertNosList = new ArrayList<>(recycleTimes);
                        List<String> certNos = null ;
                        int index = 0;
                        for(String certNo : certNoList){
                            ++index;
                            if(index == 1 || index % 800 == 0 ){
                                if(index % 800 == 0){
                                    grpMemberCertNosList.add(certNos);
                                }
                                certNos = new ArrayList<>(800);
                            }
                            certNos.add(certNo);
                            if(index == certNoList.size()){
                                grpMemberCertNosList.add(certNos);
                            }
                        }
                        for(List<String> memberCertNoList : grpMemberCertNosList){
                            cstQC.setCertNoList(memberCertNoList);
                            if(null == cstBscInfoVOList){
                                cstBscInfoVOList = this.cstBscInfoService.searchListByCon(cstQC);
                            }else{
                                cstBscInfoVOList.addAll(this.cstBscInfoService.searchListByCon(cstQC));
                            }
                        }
                    }else{
                        cstQC.setCertNoList(certNoList);
                        cstBscInfoVOList = cstBscInfoService.searchListByCon(cstQC);
                    }
                    if (CollectionUtils.isNotEmpty(cstBscInfoVOList)) {
                        for (CstBscInfoVO cstBscInfoVO : cstBscInfoVOList) {
                            if(rlPsnCertNoAndLnkIdsMap.containsKey(cstBscInfoVO.getCertNo())){
                                lnkCompIdList = rlPsnCertNoAndLnkIdsMap.get(cstBscInfoVO.getCertNo());
                            }else{
                                lnkCompIdList = null ;
                            }
                            if(null != lnkCompIdList){
                                for (Long lnkCompId : lnkCompIdList) {
                                    if (splIdAndGrpIdMap.containsKey(lnkCompId)) {
                                        if (grpIdAndCstIdsMap.containsKey(lnkCompIdAndGrpIdMap.get(lnkCompId))) {
                                            cstIdlist = grpIdAndCstIdsMap.get(lnkCompIdAndGrpIdMap.get(lnkCompId));
                                        }else{
                                            cstIdlist = new ArrayList<>();
                                        }
                                        if(!cstIdlist.contains(cstBscInfoVO.getId())){
                                            cstIdlist.add(cstBscInfoVO.getId());
                                            grpIdAndCstIdsMap.put(lnkCompIdAndGrpIdMap.get(lnkCompId), cstIdlist);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    certNoList.clear();
                }
            }

            if (CollectionUtils.isMapNotEmpty(grpIdAndCstIdsMap)) {
                for (Map.Entry<Long,List<Long>> entry : grpIdAndCstIdsMap.entrySet()) {
                    Long total = 0L;
                    if (CollectionUtils.isNotEmpty(entry.getValue())) {
                        List<SplGrpPrjBizViewDTO> dtoList = null ;
                        List<List<Long>> cstIdsList = null ;
                        SplGrpPrjBizViewQC qc = new SplGrpPrjBizViewQC();
                        qc.setCstRlCd(2);
                        if(entry.getValue().size() > 1000){
                            int recycleTimes = entry.getValue().size() % 800 == 0 ? entry.getValue().size()/800 : entry.getValue().size()/800 + 1 ;
                            cstIdsList = new ArrayList<>(recycleTimes);
                            List<Long> cstIds = null ;
                            int index = 0;
                            for(Long cstId : entry.getValue()){
                                ++index;
                                if(index == 1 || index % 800 == 0 ){
                                    if(index % 800 == 0){
                                        cstIdsList.add(cstIds);
                                    }
                                    cstIds = new ArrayList<>(800);
                                }
                                cstIds.add(cstId);
                                if(index == entry.getValue().size()){
                                    cstIdsList.add(cstIds);
                                }
                            }
                            for(List<Long> cstIdList : cstIdsList){
                                qc.setCstIds(cstIdList);
                                if(null == dtoList){
                                    dtoList = this.splGrpPrjBizViewApiService.searchtGrpLoanGuarDataAnalysisDTO(qc);
                                }else{
                                    dtoList.addAll(this.splGrpPrjBizViewApiService.searchtGrpLoanGuarDataAnalysisDTO(qc));
                                }
                            }
                        }else{
                            qc.setCstIds(entry.getValue());
                            dtoList = this.splGrpPrjBizViewApiService.searchtGrpLoanGuarDataAnalysisDTO(qc);
                        }
                        for (SplGrpPrjBizViewDTO splGrpPrjBizViewDTO : dtoList) {
                            total += StringUtils.isNotEmpty(splGrpPrjBizViewDTO.getActLsAmt()) ? splGrpPrjBizViewDTO.getActLsAmt() : 0L;
                            //groupIdAndGrpInfoMap.get(entry.getKey()).setGuaranteeTotal(total);
                        }
                    }
                    groupIdAndGrpInfoMap.get(entry.getKey()).setGuaranteeTotal(total);
                }
            }
        }
    }
}
